package cn.lzh.quartzadmin.biz.impl;

import cn.lzh.quartzadmin.biz.IQrtzAuthService;
import cn.lzh.quartzadmin.dao.QrtzAdminAuthMapper;
import cn.lzh.quartzadmin.po.QrtzAdminAuth;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class QrtzAuthServiceImpl implements IQrtzAuthService {

    @Resource
    private QrtzAdminAuthMapper adminAuthMapper;


    @Override
    public Boolean appKeyExistInDb(String appKey) {
        QrtzAdminAuth adminAuth = adminAuthMapper.selectByPrimaryKey(appKey);
        if (adminAuth == null) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public Boolean appSecretIsCorrect(String headerAppKey, String headerAppSecret) {
        QrtzAdminAuth adminAuth = adminAuthMapper.selectByPrimaryKey(headerAppKey);
        if (adminAuth == null) {
            return false;
        } else if (!StringUtils.equals(adminAuth.getAppSecret(), headerAppSecret)) {
            return false;
        } else {
            return true;
        }
    }
}
